package com.sitia.jd.controller;

import com.sitia.common.annotation.Log;
import com.sitia.common.core.controller.BaseController;
import com.sitia.common.core.domain.AjaxResult;
import com.sitia.common.core.page.TableDataInfo;
import com.sitia.common.enums.BusinessType;
import com.sitia.common.utils.poi.ExcelUtil;
import com.sitia.jd.domain.MxRebateActivity;
import com.sitia.jd.service.IMxRebateActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 返利活动Controller
 * 
 * @author sitia
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/jd/activity")
public class MxRebateActivityController extends BaseController
{
    @Autowired
    private IMxRebateActivityService mxRebateActivityService;

    /**
     * 查询返利活动列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MxRebateActivity mxRebateActivity)
    {
        startPage();
        List<MxRebateActivity> list = mxRebateActivityService.selectMxRebateActivityList(mxRebateActivity);
        return getDataTable(list);
    }

    /**
     * 导出返利活动列表
     */
    @Log(title = "返利活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MxRebateActivity mxRebateActivity)
    {
        List<MxRebateActivity> list = mxRebateActivityService.selectMxRebateActivityList(mxRebateActivity);
        ExcelUtil<MxRebateActivity> util = new ExcelUtil<MxRebateActivity>(MxRebateActivity.class);
        util.exportExcel(response, list, "返利活动数据");
    }

    /**
     * 获取返利活动详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mxRebateActivityService.selectMxRebateActivityById(id));
    }

    /**
     * 新增返利活动
     */
    @Log(title = "返利活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MxRebateActivity mxRebateActivity)
    {
        return toAjax(mxRebateActivityService.insertMxRebateActivity(mxRebateActivity));
    }

    /**
     * 修改返利活动
     */
    @Log(title = "返利活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MxRebateActivity mxRebateActivity)
    {
        return toAjax(mxRebateActivityService.updateMxRebateActivity(mxRebateActivity));
    }

    /**
     * 删除返利活动
     */
    @Log(title = "返利活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mxRebateActivityService.deleteMxRebateActivityByIds(ids));
    }
}
